﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace WindowsGame1
{
    public static class Helpers
    {
        static SpriteBatch sb;
        static Texture2D pixel;
        //public static Helpers instance;

        //public Helpers() {
         ///   instance = this;
        //}

        public static void Init(SpriteBatch s, GraphicsDeviceManager g) {
            sb = s;
            pixel = new Texture2D(g.GraphicsDevice, 1, 1);
            Color[] col = new Color[1];
            col[0] = Color.White;
            pixel.SetData<Color>(col);
        
        }

        public static void drawLine(Vector2 p1, Vector2 p2) {
            double deltax = p2.X - p1.X;
            double deltay = p2.Y - p1.Y;
            double linesize = Math.Sqrt(deltax * deltax + deltay * deltay);
            double angle = Math.Atan2(deltay, deltax);

            sb.Draw(pixel, p1, new Rectangle(0, 0, 1, 1), Color.White, (float)angle, Vector2.Zero, new Vector2((float) linesize, 1), SpriteEffects.None, 0);
             
        }

        public static void drawRect(Vector2 p1, Vector2 p2)
        {
            drawLine(new Vector2(p1.X,p1.Y), new Vector2(p2.X,p1.Y));
            drawLine(new Vector2(p2.X, p1.Y), new Vector2(p2.X, p2.Y));
            drawLine(new Vector2(p2.X, p2.Y), new Vector2(p1.X, p2.Y));
            drawLine(new Vector2(p1.X, p2.Y), new Vector2(p1.X, p1.Y));
        }

        public static void drawAABB(Vector2 p1, Vector2 p2)
        {
            float minx;
            float maxx;
            float miny;
            float maxy;

            if (p1.X < p2.X) 
            {
                minx = p1.X;
                maxx = p2.X;
            } else {
                minx = p1.X;
                maxx = p2.X;            
            }
            if (p1.Y < p2.Y) 
            {
                miny = p1.Y;
                maxy = p2.Y;
            } else {
                miny = p1.Y;
                maxy = p2.Y;            
            }

            drawLine(new Vector2(minx, miny), new Vector2(maxx, miny));
            drawLine(new Vector2(maxx, miny), new Vector2(maxx, maxy));
            drawLine(new Vector2(maxx, maxy), new Vector2(minx, maxy));
            drawLine(new Vector2(minx, maxy), new Vector2(minx, miny));
            
        }

        public static Rectangle getCollisionRect(Vector2 p1, Vector2 p2)
        {

            Rectangle rr = new Rectangle();



            return rr;
        }
    }
}
